﻿//Author:TQ
using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;

namespace TQ.Sharepoint.Webparts.Microblogger
{
    [ToolboxItemAttribute(false)]
    public class Microblogger : WebPart
    {
        // Visual Studio might automatically update this path when you change the Visual Web Part project item.
        private const string _ascxPath = @"~/_CONTROLTEMPLATES/TQ.Sharepoint.Webparts/Microblogger/MicrobloggerUserControl.ascx";

        private int _numItems = 0;
        private int _numDays = 0;

        [Personalizable(PersonalizationScope.Shared)]
        [WebBrowsable(true)]
        [Category("Configurations")]
        [WebDisplayName("No. of Days")]
        [Description("Maximum number of days ago of a comment")]
        public int numDays
        {
            get
            {
                if (_numDays == 0)
                    _numDays = 30;//default number
                return _numDays;
            }
            set
            { _numDays = value; }
        }

        [Personalizable(PersonalizationScope.Shared)]
        [WebBrowsable(true)]
        [Category("Configurations")]
        [WebDisplayName("Items per page")]
        [Description("Number of items per page result")]
        public int numItems
        {
            get
            {
                if (_numItems == 0)
                    _numItems = 10;//default number
                return _numItems;
            }
            set
            { _numItems = value; }
        }



        protected override void CreateChildControls()
        {
            MicrobloggerUserControl control =(MicrobloggerUserControl)Page.LoadControl(_ascxPath);
            control.numItems = numItems;
            control.numDays = numDays;
            Controls.Add(control);
        }
    }
}
